package LeetCode.linkednode;

public class BM_9 {
    public ListNode removeNthFromEnd (ListNode head, int n) {
        ListNode cur = head;
        int length = 0;
        while (cur != null){
            cur = cur.next;
            length++;
        }
        cur = head;
        if(n == length){
            return head.next;
        }
        while (length - n - 1 > 0){
           cur = cur.next;
           length--;
        }
        cur.next = cur.next.next;
        return head;
    }
}
